<template>
<view>
<view class="nodata_txt" v-if="orgList.length===0">暂无相关数据~</view>
<view v-for="(item, idx) in orgList" :key="idx" @tap="toDetail" class="org_sec flex" :data-org-id="item.id">
    <image mode="scaleToFill" :src="item.imageUrl?item.imageUrl:'/static/images/defaultorg.png'"></image>
    <view class="desc flex">
        <view class="title">{{item.name}}</view>
        <view class="time">{{item.check_status==1?'审核时间':'申请时间'}}：{{item.applyTime}}</view>
    </view>
    <view @tap="toQuitOrg" class="status checking" :data-org-id="item.departmentid" :data-org-name="item.full_name" v-if="item.check_status==1">已通过</view>
    <view class="status refused" v-if="item.check_status==2">已驳回</view>
    <view class="status" v-if="item.check_status==0">待审核</view>
</view>
</view>
</template>

<script>
var t = require("../../../utils/request.js"),
    e = function (t) {
  return t && t.__esModule ? t : {
    default: t
  };
}(require("../../../utils/api.js")),
    a = require("../../../utils/util.js"),
    app = getApp(),
    myOrgList = e.default.departmantOrgList,
		departmentList = e.default.departmentList,
    i = e.default.departmentQuit;

export default {
  data() {
    return {
      page: 1,
      noMore: !1,
      orgList: []
    };
  },

  components: {},
  props: {},
  onLoad: function (t) {
    this.getOrgList();
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {
    this.setData({
      page: 1,
      noMore: !1
    }), this.getOrgList("refresh");
  },
  onReachBottom: function () {
    if (!this.noMore) {
      var t = this.page;
      this.setData({
        page: ++t
      }), this.getOrgList();
    }
  },
  onShareAppMessage: function () {
    return {
      title: "让公益更生活 让生活更公益",
      path: "/pages/index/index",
      imageUrl: "/static/images/zyh_logo.jpg"
    };
  },
  methods: {
    getOrgList: function () {
      var e = this,
          i = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "load",
          r = {
        data: {
          api: myOrgList,
          pageNo: this.page,
          pageSize: 10,
					uid: '1426011501830979585', // app.globalData.zyzId,
        },
        token: app.globalData.token
      };
      return (0, t.request)(r, "normal", !0).then(function (t) {
        if (t.data.success) {
          t.data.data.rows.length < 10 && e.setData({
            noMore: !0
          });
          var o = e.orgList,
              n = [];
          t.data.data.rows.forEach(function (t) {
            t.name = t.name.length > 12 ? t.name.substr(0, 12) + "..." : t.name;
						t.applyTime = (0, a.formatTimeTwo)(t.regTime, "Y年M月D日"), n.push(t);
          }), "refresh" === i ? e.setData({
            orgList: n
          }) : e.setData({
            orgList: o.concat(n)
          });
        }
      });
    },
    toQuitOrg: function (t) {
      var e = this,
          o = t.currentTarget.dataset,
          n = o.orgId;
      "社会志愿者" !== o.orgName ? uni.showModal({
        title: "温馨提示",
        content: "确定退出此组织吗？",
        showCancle: !0,
        cancelText: "再看看",
        cancelColor: "#333333",
        confirmText: "立即退出",
        confirmColor: "#24CBA9",
        success: function (t) {
          t.confirm && e.quitOrgRequest(n).then(function (t) {
            t.data.errCode === a.ERR_OK ? (e.setData({
              page: 1,
              noMore: !1
            }), e.getOrgList("refresh")) : uni.showToast({
              title: t.data.message,
              icon: "none"
            });
          });
        }
      }) : uni.showToast({
        icon: "none",
        title: "社会志愿者不可退出！"
      });
    },
    quitOrgRequest: function (e) {
      var a = {
        data: {
          api: i,
          id: e
        },
        token: app.globalData.token
      };
      return (0, t.request)(a, "common", !0);
    },
    toDetail: function (t) {
      uni.navigateTo({
        url: "/pages/org/detail?id=" + t.currentTarget.dataset.orgId
      });
    }
  }
};
</script>
<style>
page {
    min-height: 100%;
    background: #f4f4f4;
    padding: 20rpx 0 74rpx;
}

.org_sec,page {
    width: 100%;
    height: auto;
}

.org_sec {
    justify-content: space-around;
    min-height: 144rpx;
    padding: 30rpx;
    margin-bottom: 10rpx;
    background: #fff;
}

.org_sec image {
    flex: 0 0 80rpx;
    width: 80rpx;
    height: 80rpx;
    margin-right: 30rpx;
}

.org_sec .desc {
    flex: 0 0 440rpx;
    width: 440rpx;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
}

.org_sec .desc .title {
    margin-bottom: 20rpx;
    font-size: 30rpx;
}

.org_sec .desc .time {
    font-size: 24rpx;
}

.org_sec .status {
    flex: 0 0 136rpx;
    width: 136rpx;
    height: 44rpx;
    line-height: 44rpx;
    text-align: center;
    background: #f2f2f2;
    font-size: 26rpx;
    color: #666;
}

.org_sec .status.checking {
    background: #fff1e4;
    color: #f76500;
}

.org_sec .status.refused {
    background: #ffefef;
    color: #e60012;
}
</style>